import { fromEvent } from "rxjs";
import { tap, map, filter, bufferCount } from "rxjs/operators";
import { getLogger } from "../utils";

const log0 = getLogger("Purpose");
log0("Demonstrating how to trigger when a special sequence of keys are pressed, e.g. asdf");

const keyDown$ = fromEvent(document, "keydown").pipe(map((e: KeyboardEvent) => e.key));

const TARGET = "asdf";

keyDown$
    .pipe(
        tap(char => console.log(char)),
        bufferCount(TARGET.length),
        map(chars => chars.join("")),
        filter(word => word === TARGET),
    )
    .subscribe(() => {
        alert('you just keyed in asdf!');
        // console.log('you just keyed in asdf!');
    });